﻿using System;
using NHibernate;
using NHibernate.Cfg;

namespace FrameServer.Mysql
{
    class SessionFactory
    {
        private static ISessionFactory sessionFactory;
        public static ISessionFactory MSessionFactory
        {
            get
            {
                if (sessionFactory == null)
                {
                    var configuration = new Configuration();
                    configuration.Configure("Mysql/hibernate.cfg.xml");//解析hibernate.cfg.xml
                    configuration.AddAssembly("FrameServer");
                    sessionFactory = configuration.BuildSessionFactory();
                }
                return sessionFactory;
            }
        }

        public static ISession OpenSession()
        {
            return MSessionFactory.OpenSession();
        }
    }
}

